package com.accp.jboa.action;

import com.accp.jboa.biz.Checkbiz;
import com.accp.jboa.pojo.Check;
import com.accp.jboa.pojo.Employee;
import com.accp.jboa.vo.EmployeeAndLeaveAndCheckVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/api/check")
public class CheckAction {
//    Integer checkid;
    @Autowired(required = false)
    private Checkbiz checkbiz;

    @PostMapping("upd")
    public Map<String,String> updCheck(@RequestBody Check check){
        Map<String,String> map = new HashMap<>();
//        if (checkid!=null) {
//            check.setCheckid(checkid);
//        }
        int i = checkbiz.update(check);
        if (i>0){
            map.put("code","200");
            map.put("msg","添加成功");
            return map;
        }else {
            map.put("code","400");
            map.put("msg","添加失败");
            return map;
        }
    }

    @GetMapping("querycheckid/{id}")
    public Map<String,String> querynextdealman(@PathVariable int id){
        Map<String,String> map = new HashMap<>();
        EmployeeAndLeaveAndCheckVo querynextdealman = checkbiz.querynextdealman(id,null);
        if (querynextdealman!=null){
            map.put("code","200");
            map.put("msg","查询成功");
            map.put("checkid",querynextdealman.getCheckid().toString());
            return map;
        }else {
            map.put("code","400");
            map.put("msg","查询失败");
            return map;
        }
    }


    @GetMapping("querynextdealman/{id}")
    public Map<String,String> querycheckid(@PathVariable int id){
        Map<String,String> map = new HashMap<>();
        String pid = checkbiz.querynextdealman(id);
        if (pid!=null){
            map.put("code","200");
            map.put("msg","查询成功");
            map.put("nextdealman",pid);
            return map;
        }else {
            map.put("code","400");
            map.put("msg","查询失败");
            return map;
        }
    }
    @PostMapping("add")
    public Map<String,String> addCheck(@RequestBody Check check){
        Map<String,String> map = new HashMap<>();
        int i = checkbiz.insert(check);
        if (i>0){
            map.put("code","200");
            map.put("msg","添加成功");
            return map;
        }else {
            map.put("code","400");
            map.put("msg","添加失败");
            return map;
        }
    }


    @PostMapping("insert")
    public Map<String,String> insertCheck(@RequestBody Check check){
        Map<String,String> map = new HashMap<>();
        System.out.println("----------------------------------");
        int i = checkbiz.insertCheck(check);
        if (i>0){
            map.put("code","200");
            map.put("msg","添加成功");
            return map;
        }else {
            map.put("code","400");
            map.put("msg","添加失败");
            return map;
        }
    }
}
